﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ElCharro01.Models;

namespace ElCharro01.Areas.User.Controllers
{ 
    public class CustomerController : Controller
    {
        private Entities db = new Entities();

        public ActionResult Edit()
        {
            int id = (int)Session["UserId"];
            Customer customer = (Customer) db.UserSet.Single(c => c.ID == id);
            return View(customer);
        }

        //
        // POST: /User/Customer/Edit/5

        [HttpPost]
        public ActionResult Edit(Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.UserSet.Attach(customer);
                db.ObjectStateManager.ChangeObjectState(customer, EntityState.Modified);
                db.SaveChanges();

                return RedirectToAction("Edit", "Customer", new { area = "User" });
            }
            return View(customer);
        }

        public ActionResult ShowBonusAndRecruited()
        {
            int id = (int)Session["UserId"];
            Customer customer = (Customer)db.UserSet.Single(c => c.ID == id);
            return View(customer);
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}